import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:transparent_image/transparent_image.dart';

class Imagedemo extends StatefulWidget {
  const Imagedemo({super.key});

  @override
  State<Imagedemo> createState() => _ImagedemoState();
}

/*  Image支持如下几种类型的构造函数:
    。new Image-用于从Imag eProvider获取图像;
    。new Image.asset-使用key 从AssetBundle获得的图豫;
    。new Image.network-从网络URL中获取图片:
    。new Image.file-从本地文件中获取图片;
    。new Image.memory-用于从Uint8List获取图像;*/

class _ImagedemoState extends State<Imagedemo> {
  @override
  Widget build(BuildContext context) {
    var url =
        "https://ds1028.tocmcc.cn/QQ2022/Albums/%E5%85%B6%E4%BB%96/%E6%88%91%E7%9A%84%E7%9B%B8%E5%86%8C/032_2022-10-28_ACB78C9B.png";
    var file_url =
        "/data/user/0/com.zhf.flutter1/cache/0b2e312b-571c-45c2-9dd7-ffbb8ea5ad2e/jin.jpg";
    return Scaffold(
      appBar: AppBar(title: Text("Image 加载的方法")),
      body: Container(
        child: Wrap(
          spacing: 8,
          runSpacing: 6,
          children: [
            Image.file(File(file_url), height: 100),
            Image.network(url, height: 140),
            FadeInImage.memoryNetwork(
                height: 140, placeholder: kTransparentImage, image: url),
            FadeInImage.assetNetwork(
                height: 140, placeholder: 'images/dan.jpg', image: url),
            CachedNetworkImage(
              height: 140,
              imageUrl: url,
              placeholder: (context, url) => CircularProgressIndicator(),
            ),
            const Image(height: 100, image: AssetImage('images/dan.jpg')),
            Image.asset('images/dan.jpg', height: 100),
            const Icon(Icons.android, size: 100, color: Colors.green),
            Icon(IconData(0x91d1, fontFamily: 'china'),
                size: 100, color: Colors.blue),
          ],
        ),
      ),
    );
  }
}
